// Configuration.cpp: implementation of the CConfiguration class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Configuration.h"
#include <global.h>
#include <log.h>

CConfiguration cfg;

bool CConfiguration::m_ifDebug= false;
CString CConfiguration::m_strIP;
CString CConfiguration::m_strReAuthURI;

//////////////////////////////////////////////////////////////////////
// Interface
//////////////////////////////////////////////////////////////////////

const CString CConfiguration::m_strCfgFileName(CString(_T("./"))+FILTER_NAME+_T(".ini"));

#ifdef _DEBUG
#include <addin.h>
#endif
bool CConfiguration::IsDebugModule()
{
#ifdef _DEBUG
LogEventText( _T("%s(Debug): CConfiguration::IsDebugModule(): call"), NULLHANDLE, NOERROR, FILTER_NAME );
#endif
	static bool ifLoad= false;
	if (false == ifLoad)
	{
#ifdef _DEBUG
LogEventText( _T("%s(Debug): CConfiguration::IsDebugModule(): Load"), NULLHANDLE, NOERROR, FILTER_NAME );
LogEventText( _T("%s(Debug): CConfiguration::IsDebugModule(): CfgFile='%s'"), NULLHANDLE, NOERROR, FILTER_NAME, (LPCTSTR)m_strCfgFileName );
#endif
		const CString DEBUG_OFF= _T("off");
		CString strIfDebug;
			::GetPrivateProfileString( _T("Other"), _T("Debug"), DEBUG_OFF, strIfDebug.GetBuffer(MAX_PATH), MAX_PATH, m_strCfgFileName );
			strIfDebug.ReleaseBuffer();
#ifdef _DEBUG
LogEventText( _T("%s(Debug): CConfiguration::IsDebugModule(): strIfDebug='%s'"), NULLHANDLE, NOERROR, FILTER_NAME, (LPCTSTR)strIfDebug );
#endif
		if (0 == strIfDebug.CompareNoCase( DEBUG_OFF ))
			m_ifDebug = false;
		else
			m_ifDebug = true;

		ifLoad = true;
	}

#ifdef _DEBUG
	LogEventText( _T("%s(Debug): CConfiguration::IsDebugModule(): return %s"), NULLHANDLE, NOERROR, FILTER_NAME, ((true==m_ifDebug) ? _T("true") : _T("false")) );
#endif
	return( m_ifDebug );
}

CString& CConfiguration::GetComIP()
{
#ifdef _DEBUG
LogEventText( _T("%s(Debug): CConfiguration::GetComIP(): call"), NULLHANDLE, NOERROR, FILTER_NAME );
#endif
	static bool ifLoad= false;
	if (false == ifLoad)
	{
		::GetPrivateProfileString( _T("COM"), _T("IP"), "", m_strIP.GetBuffer(MAX_PATH), MAX_PATH, m_strCfgFileName );
			m_strIP.ReleaseBuffer();

		ifLoad = true;
	}
	return( m_strIP );
}

CString& CConfiguration::GetReAuthURI()
{
#ifdef _DEBUG
LogEventText( _T("%s(Debug): CConfiguration::IsDebugModule(): call"), NULLHANDLE, NOERROR, FILTER_NAME );
#endif
	static bool ifLoad= false;
	if (false == ifLoad)
	{
		::GetPrivateProfileString( _T("DOMINO"), _T("ReAuthURI"), "Location: /names.nsf?login", m_strReAuthURI.GetBuffer(MAX_PATH), MAX_PATH, m_strCfgFileName );
			m_strReAuthURI.ReleaseBuffer();
		m_strReAuthURI += _T("\r\n\r\n");

		ifLoad = true;
	}
	return( m_strReAuthURI );
}

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CConfiguration::CConfiguration()
{
}

CConfiguration::~CConfiguration()
{

}
